import { defineStore } from "pinia";
import type { CategoryState } from "./interface/index";
import {
  getCategoryOneList,
  getCategoryTwoList,
  getCategoryThreeList,
} from "@/api/product/Categorymark";
export const useCategoryStore = defineStore("category", {
  state: (): CategoryState => {
    return {
      // 初始值
      category1Id: undefined,
      category2Id: undefined,
      category3Id: undefined,
      category1List: [],
      category2List: [],
      category3List: [],
    };
  },
  getters: {},
  actions: {
    async getCategoryOneList() {
      this.category1List = await getCategoryOneList();
    },
    async getCategoryTwoList(category1Id: number) {
      this.category2List = await getCategoryTwoList(category1Id);
      this.category2Id = undefined;
      this.category3Id = undefined;
      this.category3List = [];
    },
    async getCategoryThreeList(category2Id: number) {
      this.category3List = await getCategoryThreeList(category2Id);
      this.category3Id = undefined;
    },
  },
});
